export default {
	id: 'menu',
	state: () => {
		return {
			breadList: [],
			routePath: {
				path: '/',
				name: '首页',
			},
			tabList: [
				{
					path: '/',
					name: '首页',
				},
			],
		};
	},
	getters: {},
	actions: {
		// 设置设置 navBar
		setBreadList(payload) {
			this.breadList = payload;
		},
		// 保存活跃的 uri
		setRoutePath(payload) {
			this.routePath = payload;
		},
		// 添加 tab 窗口
		setTabList(payload) {
			let flag = false;
			for (const key of this.tabList) {
				if (key.path === payload.path || key.name === payload.name) {
					flag = true;
				}
			}
			if (!flag) {
				this.tabList.push(payload);
			}
		},
		// 默认刷新保存的页面
		clearTabList(payload) {
			this.tabList = [
				{
					path: '/',
					name: '首页',
				},
			];
			if (payload.path !== '/' || payload.name !== '首页') {
				this.tabList.push({
					path: payload.path,
					name: payload.name,
				});
			}
		},
		shutdownTag(tagName) {
			let ret = null;
			this.tabList = this.tabList.filter((item) => {
				if (item.name !== tagName) {
					ret = item;
					return true;
				} else {
					return false;
				}
			});

			return ret;
		},
	},
	// 开启数据缓存
	persist: {
		enabled: true,
		strategies: [
			{
				key: 'menuInfo',
				storage: localStorage,
				// 存储 state 中的属性信息
				paths: ['breadList', 'routePath', 'tabList'],
			},
		],
	},
};
